<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
<!--          <p class="login-tip">输入任意用户名和密码即可</p>-->
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import { mapActions } from 'vuex'
export default {
  components: {
    LoginForm
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'getUserInfo'
    ]),
    handleSubmit ({ userName, password }) {
      let post_data = { username: userName, password: password }
      this.$axios.post('/api/user_login/', this.qs.stringify(post_data)).then((response) => {
        if (response.data.success) {
          console.log('登陆成功')
          this.handleLogin({ userName: 'super_admin', password: 'fnahfahf' }).then(res => {
            console.log('login...')
            this.getUserInfo().then(res => {
              this.$router.push({
                name: this.$config.homeName
              })
            })
          })
        } else {
          alert('用户名或密码不正确')
        }
      }).catch((response) => {
        console.log(response)
      })
    }
  }
}
</script>

<style>

</style>
